import '/@/design/index.less';
import 'virtual:windi-base.css';
import 'virtual:windi-components.css';
import 'virtual:windi-utilities.css';
import 'virtual:svg-icons-register';
import App from './App.vue';
import { createApp } from 'vue';
import { initAppConfigStore } from '/@/logics/initAppConfig';
import { setupErrorHandle } from '/@/logics/error-handle';
import { router, setupRouter } from '/@/router';
import { setupRouterGuard } from '/@/router/guard';
import { setupStore } from '/@/store';
import { setupGlobDirectives } from '/@/directives';
import { setupI18n } from '/@/locales/setupI18n';
import { registerGlobComp } from '/@/components/registerGlobComp';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import { getToken } from '/@/utils/auth';
import Particles from 'particles.vue3';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
router.beforeEach((to, from, next) => {
  NProgress.start();
  const flag = getToken(); //获取点击登录按钮时所设置的 sessionStorage
  if (to.path === '/system/wgscreen') {
    //如果想要跳转home或者algsmanager页面必须判断有没有sessionStorage
    if (flag) {
      //如果有sessionStorage
      next('/screen'); //跳转
    } else {
      next('/login'); //还在登录页
    }
  } else {
    next();
  }
});

router.afterEach(() => {
  NProgress.done();
});

if (import.meta.env.DEV) {
  import('ant-design-vue/dist/antd.less');
}
async function bootstrap() {
  const app = createApp(App);
  app.use(Particles);
  // Configure store
  setupStore(app);

  // Initialize internal system configuration
  initAppConfigStore();
  app.use(Antd);
  // Register global components
  registerGlobComp(app);

  // Multilingual configuration
  // Asynchronous case: language files may be obtained from the server side
  await setupI18n(app);

  // Configure routing
  setupRouter(app);

  // router-guard
  setupRouterGuard(router);

  // Register global directive
  setupGlobDirectives(app);

  // Configure global error handling
  setupErrorHandle(app);

  // https://next.router.vuejs.org/api/#isready
  // await router.isReady();

  app.mount('#app');
}

bootstrap();
